﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyLibrary.ThreeLayer.Entity
{
    [AttributeUsage(AttributeTargets.Class)]
    public abstract class ValidateAttribute : System.Attribute
    {
        private bool _allowEmpty = true;

        public ValidateAttribute(bool allowEmpty)
        {
            this._allowEmpty = allowEmpty;
        }

        public ValidateAttribute()
        {
        }

        /// <summary>
        /// 字段域是否允许为空
        /// </summary>
        public bool AllowEmpty
        {
            get
            {
                return this._allowEmpty;
            }
            set
            {
                this._allowEmpty = value;
            }
        }

        /// <summary>
        /// 验证是否为空
        /// </summary>
        protected virtual bool ValidateAllowEmpty(object value)
        {
            if (this._allowEmpty) return true;
            return String.IsNullOrEmpty(value.ToString());
        }
    }

    /// <summary>
    /// 验证属性的接口
    /// </summary>
    /// <typeparam name="Type">验证的类型</typeparam>
    public interface IValidateAttribute<Type>
    {
        Type Default { get; set; }
        bool IsValidate(Type value);
    }
}
